package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.EmpJob;
import com.itheima.pojo.StudentCount;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;

    //员工职位人数统计
    @Override
    public EmpJob getEmpJobData() {
//        Map:jobName='教研主管',dataCount=1这相当于有两个map装在集合中
        List<Map<String,Object>> map = reportMapper.getEmpJobData();

        List<Object> jobName = map.stream().map(name -> name.get("jobName")).toList();
        List<Object> dataCount = map.stream().map(data -> data.get("dataCount")).toList();

        return new EmpJob(jobName,dataCount);
    }


    //员工性别统计
    @Override
    public List<Map<String,Object>> getEmpGenderData() {
        return reportMapper.getEmpGenderData();
        /*
        * List<Map<String, Object>> result = empMapper.getEmpGenderData();
            return result.stream().map(map -> {
                Map<String, Object> newMap = new HashMap<>();
                newMap.put("name", map.get("genderName"));
                newMap.put("value", map.get("value"));
                return newMap;
            }).collect(Collectors.toList());
        * */
    }

    //学员学历统计
    @Override
    public List<Map<String, Object>> getStudentGenderData() {
        return reportMapper.getStudentGenderData();
    }

    //班级人数统计
    @Override
    public StudentCount getStudentCountData() {
        List<Map<String, Object>> mapList = reportMapper.getStudentCountData();

        List<Object> clazzName = mapList.stream().map(clazz -> clazz.get("clazzName")).toList();
        List<Object> clazzData = mapList.stream().map(data -> data.get("clazzData")).toList();

        return new StudentCount(clazzName, clazzData);
    }

}
